Skip to content

socket: decode receive timestamps on a 32-bit system with a 64-bit time_t - #516

Open
WiFiGUY512 wants to merge 1 commit into
ucode-lang:masterfrom
WiFiGUY512:socket-timestamp-32bit
Open

WiFiGUY512 wants to merge 1 commit into
ucode-lang:masterfrom
WiFiGUY512:socket-timestamp-32bit

Conversation

@WiFiGUY512

Copy link
Copy Markdown

On a 32-bit system with a 64-bit time_t and musl, every SO_TIMESTAMP and SO_TIMESTAMPNS receive timestamp reaches the script in whole seconds: { sec, usec: 0 } and { sec, nsec: 0 }.

musl names a single SO_TIMESTAMP and SO_TIMESTAMPNS, with no _OLD and _NEW variants, and on a 32-bit system they are the kernel's _NEW values (63 and 64 on ARM), whose control messages carry 64-bit fields. Without SO_TIMESTAMP_NEW the _NEW decoders are compiled out, and the _OLD fallbacks (defined to SO_TIMESTAMP and SO_TIMESTAMPNS since #491) decode those messages with the old { long, long } layout: tv_sec from the low half of the 64-bit seconds and the fraction from the high half, which is 0.

This builds the 64-bit-field decoders on every Linux system. Where the libc names both variants, each keeps its entry; where it names only one, that one is decoded with the layout its time_t gives. It also gives st_timeval_new its own size; it had the size of the old struct.

Tested

  • Arista W-118 (IPQ4019, armv7, musl), OpenWrt main with this on top of the ucode OpenWrt ships (dfc64d4): { sec, usec: 615067 } and { sec, nsec: 616156570 }, where it gave 0 before.
  • Arista C-260 (IPQ8074, aarch64, musl), same build: type 29 { sec, usec } and type 35 { sec, nsec }, with fractions, as before.
  • x86_64 glibc, current master with this: builds without warnings; type 29 and type 35 decode as before, with fractions.

🤖 Generated with Claude Code

…me_t

musl names one SO_TIMESTAMP and one SO_TIMESTAMPNS, with no _OLD and
_NEW variants, and on a 32-bit system they are the kernel's _NEW values
(63 and 64 on ARM), whose control messages carry 64-bit fields. Without
SO_TIMESTAMP_NEW, the _NEW decoders were left out and the _OLD fallbacks,
defined to SO_TIMESTAMP and SO_TIMESTAMPNS, decoded those messages with
the old layout: tv_sec from the low half of the 64-bit seconds and the
fraction from the high half, which is 0. Every receive timestamp came
out in whole seconds.

Build the 64-bit-field decoders on every Linux system. Where the libc
names both variants, keep an entry for each; where it names only one,
decode it with the layout its time_t gives: the 64-bit fields where
time_t is wider than long. Also give st_timeval_new its own size; it had
the size of the old struct.

Seen on an Arista W-118 (IPQ4019, armv7, musl): SO_TIMESTAMP gave
{ sec, usec: 0 } and SO_TIMESTAMPNS { sec, nsec: 0 } for every packet.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Christopher Griffin <christophergriffin05@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant